//树组件
Vue.component('ew-cate', {
  template: `
      <ul :class="'level'+level">
          <li v-for="item in model" :class="{cur:item.value==value['level'+level]}">
            <i class="fa" :class="item.show ? 'fa-minus-square-o' : 'fa-plus-square-o'" v-if="item.child" @click="toggle(item)"></i>
            <a href="javascript:;" :title="item.name" @click="change(item)"><em>{{ item.count }}</em><span>{{ item.name }}</span></a>
            <ew-cate @select-change='cateChange' v-show="item.show" v-if="item.child" :model="item.child" :field="field" :level="item.level" :value="value"></ew-cate>
          </li>
      </ul>
  `,
  props: {
    model: {},
    field:{
      type: String,
      default: ''
    },
    level:{
      type: Number,
      default: 0
    },
    value:{
      type:Object,
      default:function() {
        return {};
      }
    }
  },
  data:function(){return {
  }},
  created(){
    console.log('默认值：',this.value);
  },
  methods: {
    toggle: function (item) {
      console.log(item);
      var idx = this.model.indexOf(item)
      Vue.set(this.model[idx], 'show', !item.show)
    },
    change:function (e) {
      console.log('点击',e);
      this.$emit('select-change',{field:this.field,value:e});
    },
    cateChange:function (e) {
      this.$emit('select-change',{field:e.field,value:e.value});
    }
  }
});